const TABBAR = [{
	pagePath: "/pages/view/admin/adminPage1/adminPage1",
	text: "超管首页",
	type: "1",
}, {
	pagePath: "/pages/view/admin/adminPage2/adminPage2",
	text: "超管页2",
	type: "2",
}, {
	pagePath: "/pages/view/admin/adminPage3/adminPage3",
	text: "超管3",
	type: "3",
}, {
	pagePath: "/pages/view/admin/adminPage4/adminPage4",
	text: "超管4",
	type: "4",
}, {
	pagePath: "/pages/view/merchant/merchantPage1/merchantPage1",
	text: "商户页1",
	type: "5",
}, {
	pagePath: "/pages/view/merchant/merchantPage2/merchantPage2",
	text: "商户页2",
	type: "6",
}, {
	pagePath: "/pages/view/merchant/merchantPage3/merchantPage3",
	text: "商户页3",
	type: "7",
}, {
	pagePath: "/pages/view/user/userPage1/userPage1",
	text: "用户页1",
	type: "8",
}, {
	pagePath: "/pages/view/user/userPage2/userPage2",
	text: "用户页2",
	type: "9",
}]

const clearTabbarList = [{
	"pagePath": "/pages/defalutStart/defalutStart",
	"text": "null界面"
}, {
	"pagePath": "/pages/ber/nullPage1/nullPage2",
	"text": "null界面"
}, {
	"pagePath": "/pages/ber/nullPage1/nullPage3",
	"text": "null界面"
}, {
	"pagePath": "/pages/ber/nullPage1/nullPage4",
	"text": "null界面"
}]

function userRoleIndexPath(role) {
	if (role === '1') {
		return '/pages/view/admin/adminPage1/adminPage1'
	}
	if (role === '2') {
		return '/pages/view/merchant/merchantPage1/merchantPage1'
	}
	if (role === '3') {
		return '/pages/view/user/userPage1/userPage1'
	}
}

export const setOfficialTabbar = (role, tabList) => {
	let list = JSON.parse(JSON.stringify(TABBAR))
	let newList = []
	tabList.forEach(v => {
		let index = list.findIndex(cValue => cValue.type === v)
		if (index !== -1) {
			newList.push(list[index])
		}
	})
	let hideIndex = 4 - newList.length
	newList.forEach((v, index) => {
		uni.setTabBarItem({
			pagePath: v.pagePath,
			text: v.text,
			visible: true,
			index,
		})
	})
	if (hideIndex !== 0) {
		for (let i = 1; i <= hideIndex; i++) {
			uni.setTabBarItem({
				visible: false,
				index: 4 - i
			})
		}
	}
	return userRoleIndexPath(role)
}

export const cleaarTabbar = () => {
	clearTabbarList.forEach(v => {
		uni.setTabBarItem({
			pagePath: v.pagePath,
			text: v.text,
			iconPath: v.iconPath,
			selectedIconPath: v.selectedIconPath,
			index: v.index,
			visible: true,
		})
	})
}